<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%--
  Created by IntelliJ IDEA.
  User: 86132
  Date: 2020/10/23
  Time: 11:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>旅游宝 | 编辑游客</title>
    <!-- Tell the browser to be responsive to screen width -->
    <jsp:include page="../include/header.jsp"></jsp:include>
</head>
<body class="hold-transition sidebar-mini">
<%--整个页面 div--%>
<div class="wrapper">
    <!-- Navbar  头部导航栏 -->
    <jsp:include page="../include/nav.jsp"></jsp:include>
    <!-- /.navbar -->

    <!-- Main Sidebar Container  侧边栏 左侧边栏 -->
    <jsp:include page="../include/left.jsp"></jsp:include>

    <!-- Content Wrapper. Contains page content  中部内容区   -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1>编辑游客</h1>
                    </div>
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-right">
                            <li class="breadcrumb-item"><a href="#">首页</a></li>
                            <li class="breadcrumb-item active">编辑游客</li>
                        </ol>
                    </div>
                </div>
            </div><!-- /.container-fluid -->
        </section>
        <!-- Main content -->
        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-header">
                                <h3>订单id：${order.id}</h3>
                                <button style="width: 100px; float: right ;" type="button" onclick="toAdd()" class="btn btn-block btn-success">添加游客</button>
                            </div>
                            <!-- /.card-header -->
                            <div class="card-body">
                                <table id="example2" class="table table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th>id</th>
                                        <th>游客姓名</th>
                                        <th>游客性别</th>
                                        <th>游客身份证号</th>
                                        <th>游客电话</th>
                                        <th>游客生日</th>
                                        <th >操作</th>
                                    </tr>
                                    </thead>
                                    <tbody id="tdata">

                                    </tbody>
                                    <tfoot>

                                    </tfoot>
                                </table>
                            </div>
                            <!-- /.card-body -->
                        </div>
                        <!-- /.card -->
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.container-fluid -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper  页面 下面的 页脚-->
    <jsp:include page="../include/footer.jsp"></jsp:include>
    <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->
<div style="display: none">
    <div class="col-sm-6 tourarea">
        <div class="form-group">
            <label>选择游客</label>
            <select class="yk" name="touristSex">

            </select>
        </div>
    </div>
</div>

<!-- jQuery -->
<script src="../../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- DataTables -->
<script src="../../plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../../plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../../plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="../../plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<!-- AdminLTE App -->
<script src="../../js/adminlte.min.js"></script>
<script src="../../js/layer/layer.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../../js/demo.js"></script>
<!-- page script -->
<script>
    $(function () {
        load();
        $('#example2').DataTable({
            "paging": false,
            "lengthChange": false,
            "searching": false,
            "ordering": false,
            "info": true,
            "autoWidth": false,
            "responsive": true,
        });
    });

    //连续跳转方法
    function jump(page) {
        var keywords = $("[name='keywords']").val();
        location.href = "/tourist/list?page=" + page + "&keywords=" + keywords;
    }
    //订单id
    var orderid='${order.id}';

    //添加页面
    function toAdd() {
        $.ajax({
            url:"/order/getTouristOut",
            type:"post",
            data:{orderid:orderid},
            success:function (data) {
                var ht='';
                for (var i=0; i<data.length;i++){
                    ht +="<option value='"+data[i].id+"'>"+data[i].touristName+"</option>";

                }
                $(".yk").html(ht);

                //页面层
                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['420px', '240px'], //宽高
                    content: $('.tourarea').html(),
                    btn:"提交",
                    yes: function(){
                        var tourist_id=$(".yk")[1].value;
                        $.ajax({
                            url:"/order/addTourist",
                            type:"post",
                            data:{orderid:orderid,tourist_id:tourist_id},
                            success:function (data) {
                                location.reload();
                            }
                        })
                    }
                });
            }
        })
    }

    
    function load() {
        $.ajax({
            url:"/order/getTourist",
            type:"post",
            data:{orderid:orderid},
            success:function (data) {
                var ht='';
                for (var i=0; i<data.length;i++){
                    ht +="<tr>";
                    ht +="  <td>"+data[i].id+"</td>";
                    ht +="  <td>"+data[i].touristName+"</td>";
                    ht +="  <td>"+data[i].touristSex+"</td>";
                    ht +="  <td>"+data[i].touristIdcard+"</td>";
                    ht +="  <td>"+data[i].touristPhone+"</td>";
                    ht +="  <td>"+data[i].touristBirthday+"</td>";
                    ht +='  <td><a  href="javascript:delTourist(\''+data[i].id+'\');" class="btn btn-danger btn-sm" >删除</a></td>';
                    ht +="</tr>";

                }
                $("#tdata").html(ht);
            }
        })
    }
    function delTourist(tourist_id) {
        $.ajax({
            url:"/order/delTourist",
            type:"post",
            data:{orderid:orderid,tourist_id:tourist_id},
            success:function (data) {
                location.reload();
            }
        })
    }
</script>
</body>
</html>

